package com.ruoyi.system.service.cloudroom.impl;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.cloudroom.UrlConstant;
import com.ruoyi.common.utils.cloudroom.HttpUtil;
import com.ruoyi.system.domain.vo.cloudroom.bean.BaseDto;
import com.ruoyi.system.domain.vo.cloudroom.bean.DeviceDto;
import com.ruoyi.system.domain.vo.cloudroom.bean.RoomDto;
import com.ruoyi.system.service.cloudroom.RoomService;
import org.springframework.stereotype.Service;

@Service
public class RoomServiceImpl implements RoomService {

    @Override
    public String create() throws Exception {
        return HttpUtil.postToStr(UrlConstant.CREATE_ROOM_URL, new BaseDto().toString());
    }

    @Override
    public String delete(long roomId) throws Exception {
        return HttpUtil.postToStr(UrlConstant.DELETE_ROOM_URL, new RoomDto(roomId).toString());
    }

    @Override
    public String queryOnlineNum(String roomIds) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_ROOM_USERS_NUM_URL, new RoomDto(roomIds).toString());
    }

    @Override
    public String queryOnlineMembers(long roomId) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_ROOM_MEMBERS_URL, new RoomDto(roomId).toString());
    }

    @Override
    public String queryUsageInfo(String roomIds, String fromDate, String toDate) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_ROOM_USAGE_URL, new RoomDto(roomIds, fromDate, toDate).toString());
    }

    @Override
    public String queryAllUsageInfo(String fromDate, String toDate) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_ROOM_USAGE_ALL_URL, new RoomDto(fromDate, toDate).toString());
    }

    @Override
    public String queryRoomHistory(Long roomId, Long startTime, Long endTime, Integer pageNumber, Integer pageSize) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_ROOM_HISTORY_URL, new RoomDto(roomId, startTime, endTime, pageNumber, pageSize).toString());
    }

    @Override
    public String queryRoomHistoryParticipant(Long roomId, Integer times, Integer pageNumber, Integer pageSize) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_ROOM_HISTORY_PARTICIPANTS_URL, new RoomDto(roomId, times, pageNumber, pageSize).toString());
    }

    @Override
    public String invite(Long roomId, String uid, String nickName, String targetUrl) throws Exception {
        RoomDto roomDto = new RoomDto(roomId);
        roomDto.setUid(uid);
        roomDto.setNickName(nickName);
        roomDto.setTargetUrl(targetUrl);
        return HttpUtil.postToStr(UrlConstant.ROOM_INVITE_URL, JSON.toJSONString(roomDto));
    }

    @Override
    public String kickOut(Long roomId, String uid) throws Exception {
        RoomDto roomDto = new RoomDto(roomId);
        roomDto.setUid(uid);
        return HttpUtil.postToStr(UrlConstant.ROOM_KICKOUT_URL, JSON.toJSONString(roomDto));
    }

    @Override
    public String queryGbList(String deviceNum) throws Exception {
        return HttpUtil.postToStr(UrlConstant.QUERY_DEVICE_GB_LIST_URL, new DeviceDto(deviceNum).toString());
    }
}












